package com.taoding.springbootbase.core.demo.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taoding.springbootbase.core.demo.VO.AccountBookRelationPageVO;
import com.taoding.springbootbase.core.demo.entity.AccountBookRelation;
import com.taoding.springbootbase.core.demo.entity.AssetDetails;
import com.taoding.springbootbase.core.demo.mapper.AccountBookRelationMapper;
import com.taoding.springbootbase.core.demo.service.AccountBookRelationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 木牛盒子客户关联 服务实现类
 * </p>
 *
 * @author lxh123
 * @since 2019-12-05
 */
@Service
public class AccountBookRelationServiceImpl extends ServiceImpl<AccountBookRelationMapper, AccountBookRelation> implements AccountBookRelationService {

    @Autowired
    private AccountBookRelationMapper accountBookRelationMapper;


    //todo: 切记 导包必须道此包  com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    @Override
    public IPage<AssetDetails> selectDetailPage(AccountBookRelationPageVO vo) {
        Page<AssetDetails> pageInfo = new Page<>(vo.getCurrent(), vo.getSize());//创建分页
        return pageInfo.setRecords(accountBookRelationMapper.selectByParam(pageInfo, vo));
    }

    @Override
    public IPage<AccountBookRelation> selectDetailPage2(AccountBookRelationPageVO vo) {
        QueryWrapper<AccountBookRelation> wrapper = new QueryWrapper<AccountBookRelation>()
                .eq(StringUtils.isNotBlank(vo.getId()), "id", vo.getId())
                .eq(StringUtils.isNotBlank(vo.getCustomerId()), "customer_id", vo.getCustomerId())
                .orderByAsc("create_time");
        return accountBookRelationMapper.selectPage(new Page<>(vo.getCurrent(), vo.getSize()), wrapper);
    }
}
